package Thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 邓大帅
 * Date: 2024-01-24
 * Time: 9:12
 */
public class ThreadDemo1 {
    public static boolean isQuit = false;
    public static void main(String[] args) {
//        boolean isQuit = false 这里无法变量捕获到，因为isQuit既不是既不是常量也不是未修改的变量
        Thread thread = new Thread( () -> {
            while (!isQuit) {
                System.out.println("hello world");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        thread.start();
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        isQuit = true;
    }
}
